BL Coding xml vs xslt for troop override question

Users who are viewing this thread

Taveren

Regular
WBWF&S
A simple question (I hope) for experienced modders to answer.

If I want to make a troop overhaul to include a new upgrade pathway, can I copy the existing troopline notes from the SandboxCore folder "spnpccharacters.xml" file and copy to my override folder, make the changes, and just activate?

What I am worried about is that I have a file called "spnpccharacters.xml" in my override folder, but it only contains the information from, say the Sturgian troops, then all other information in the "spnpccharacters.xml" file will be gone. So, do I have to name the override file a new unique name? (other override mods I have looked at suggests this).

Or do I have to use a xslt file (which to me looks like you can only override existing xml info but not add new information)?

Thanks for your insights
 

NPC99

Baron
M&BWBWF&SVC
A simple question (I hope) for experienced modders to answer.

If I want to make a troop overhaul to include a new upgrade pathway, can I copy the existing troopline notes from the SandboxCore folder "spnpccharacters.xml" file and copy to my override folder, make the changes, and just activate?

What I am worried about is that I have a file called "spnpccharacters.xml" in my override folder, but it only contains the information from, say the Sturgian troops, then all other information in the "spnpccharacters.xml" file will be gone. So, do I have to name the override file a new unique name? (other override mods I have looked at suggests this).

Or do I have to use a xslt file (which to me looks like you can only override existing xml info but not add new information)?

Thanks for your insights
When you create your module from the option in the scene editor, it populates your mod's SubModule.xml file. One of its XmlNodes includes: <XmlName id="NPCCharacters" path="spnpccharacters"/> which tells the game to look in your mod's ModuleData folder for an xml called spnpccharacters.xml
If your spnpccharacters.xml only includes new troops or characters which are additional to those in ...\SandBoxCore\ModuleData\spnpccharacters.xml you don't need to do anything more and you'll get both sets in game.
If your spnpccharacters.xml includes edited troops or characters already in ...\SandBoxCore\ModuleData\spnpccharacters.xml it will overwrite all of the Sandboxcore entries apart from those relating to equipment where it will add your equipment to the Sandbox equipment, making a mess. To avoid this you need to use XSLT to delete the edited Sandboxcore troops or characters. That requires an spnpccharacters.xslt file in this format:
XML:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>
 
    <xsl:template match="NPCCharacter[@id='imperial_recruit']"/>

</xsl:stylesheet>
The first part down to </xsl:template> just tells the engine to omit the matches listed below. In this example, I've only deleted imperial_recruit. You just need to use that line and substitute the correct id. For several troops just list them under <xsl:template match="NPCCharacter[@id='imperial_recruit']"/> and before </xsl:stylesheet>

PS your spnpccharacters.xslt file needs to be in the same folder as your spnpccharacters.xml file (i.e. your mod's ModuleData folder unless you modify the path in your SubModule.xml).
PPS if you copied the whole of SandboxCore's spnpccharacters.xml to your ModuleData folder, you could use an XSLT like the example given in Taleworlds Documentation to replace all settlements rather than listing individual troops.
 
Last edited:
Upvote 1

Helerek

Recruit
// Nvm I managed to find few fixes that helped me get the whole problem out of my way. Thanks for reading and sorry for pinging you D:

When you create your module from the option in the scene editor, it populates your mod's SubModule.xml file. One of its XmlNodes includes: <XmlName id="NPCCharacters" path="spnpccharacters"/> which tells the game to look in your mod's ModuleData folder for an xml called spnpccharacters.xml
If your spnpccharacters.xml only includes new troops or characters which are additional to those in ...\SandBoxCore\ModuleData\spnpccharacters.xml you don't need to do anything more and you'll get both sets in game.
If your spnpccharacters.xml includes edited troops or characters already in ...\SandBoxCore\ModuleData\spnpccharacters.xml it will overwrite all of the Sandboxcore entries apart from those relating to equipment where it will add your equipment to the Sandbox equipment, making a mess. To avoid this you need to use XSLT to delete the edited Sandboxcore troops or characters. That requires an spnpccharacters.xslt file in this format:
XML:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>
 
    <xsl:template match="NPCCharacter[@id='imperial_recruit']"/>

</xsl:stylesheet>
The first part down to </xsl:template> just tells the engine to omit the matches listed below. In this example, I've only deleted imperial_recruit. You just need to use that line and substitute the correct id. For several troops just list them under <xsl:template match="NPCCharacter[@id='imperial_recruit']"/> and before </xsl:stylesheet>

PS your spnpccharacters.xslt file needs to be in the same folder as your spnpccharacters.xml file (i.e. your mod's ModuleData folder unless you modify the path in your SubModule.xml).
PPS if you copied the whole of SandboxCore's spnpccharacters.xml to your ModuleData folder, you could use an XSLT like the example given in Taleworlds Documentation to replace all settlements rather than listing individual troops.
Tried it out multiple times in 1.9 and doesn't seem to work.
As soon as I create xslt file (even with only 2 lines of stylesheet /stylesheet) it crashes when I open sandbox/campaing.

XML:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes"/>
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="NPCCharacter"/>
</xsl:stylesheet>

As soon as I remove that file it works all well. I even tried removing all content and only leaving first and last line. For some reason it keeps crashing when I enter campaing/sandbox.
 
Last edited:
Upvote 0

NPC99

Baron
M&BWBWF&SVC
// Nvm I managed to find few fixes that helped me get the whole problem out of my way. Thanks for reading and sorry for pinging you D:


Tried it out multiple times in 1.9 and doesn't seem to work.
As soon as I create xslt file (even with only 2 lines of stylesheet /stylesheet) it crashes when I open sandbox/campaing.

XML:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes"/>
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="NPCCharacter"/>
</xsl:stylesheet>

As soon as I remove that file it works all well. I even tried removing all content and only leaving first and last line. For some reason it keeps crashing when I enter campaing/sandbox.
I'm not surprised. Your XSLT will remove every NPCCharacter from the game - all the troops, Lords, notables, villagers etc. which the game's code expects to be there (NPCCharatcters exist in a lot more files than just spnpccharacters.xml). The example I gave only removed one NPCCharacter the imperial_recruit and would need a related xml adding back a new version of that imperial_recruit or the game would crash in its absence (unless all references to it and dependencies on it in other xmls are also edited out).
 
Last edited:
Upvote 0

Helerek

Recruit
I'm not surprised. Your XSLT will remove every NPCCharacter from the game - all the troops, Lords, notables, villagers etc. which the game's code expects to be there (NPCCharatcters exist in a lot more files than just spnpccharacters.xml). The example I gave only removed one NPCCharacter the imperial_recruit and would need a related xml adding back a new version of that imperial_recruit or the game would crash in its absence (unless all references to it and dependencies on it in other xmls are also edited out).
It was crashing due to wrong xslt code. The online xslt checker worked like a charm.
Also you can remove a unit and not replace it. The game will work fine until you see the unit on campaing map or inspect it in encyclopedia (little trivia).
 
Upvote 0

NPC99

Baron
M&BWBWF&SVC
It was crashing due to wrong xslt code. The online xslt checker worked like a charm.
Also you can remove a unit and not replace it. The game will work fine until you see the unit on campaing map or inspect it in encyclopedia (little trivia).
Read the context. It was in respect of edited NPCCharaters - i.e. together with an XML of one or more replacements. Used correctly the code works.
 
Upvote 0

Paramonov

Recruit
When you create your module from the option in the scene editor, it populates your mod's SubModule.xml file. One of its XmlNodes includes: <XmlName id="NPCCharacters" path="spnpccharacters"/> which tells the game to look in your mod's ModuleData folder for an xml called spnpccharacters.xml
If your spnpccharacters.xml only includes new troops or characters which are additional to those in ...\SandBoxCore\ModuleData\spnpccharacters.xml you don't need to do anything more and you'll get both sets in game.
If your spnpccharacters.xml includes edited troops or characters already in ...\SandBoxCore\ModuleData\spnpccharacters.xml it will overwrite all of the Sandboxcore entries apart from those relating to equipment where it will add your equipment to the Sandbox equipment, making a mess. To avoid this you need to use XSLT to delete the edited Sandboxcore troops or characters. That requires an spnpccharacters.xslt file in this format:
XML:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>
 
    <xsl:template match="NPCCharacter[@id='imperial_recruit']"/>

</xsl:stylesheet>
The first part down to </xsl:template> just tells the engine to omit the matches listed below. In this example, I've only deleted imperial_recruit. You just need to use that line and substitute the correct id. For several troops just list them under <xsl:template match="NPCCharacter[@id='imperial_recruit']"/> and before </xsl:stylesheet>

PS your spnpccharacters.xslt file needs to be in the same folder as your spnpccharacters.xml file (i.e. your mod's ModuleData folder unless you modify the path in your SubModule.xml).
PPS if you copied the whole of SandboxCore's spnpccharacters.xml to your ModuleData folder, you could use an XSLT like the example given in Taleworlds Documentation to replace all settlements rather than listing individual troops.
You just save my life dude
 
Upvote 0
Top Bottom