xml vs xslt for troop override question

Users who are viewing this thread

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
 
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
// 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
// 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
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
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
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
Sorry for reviving a dead thread (but since you linked this thread as an answer to another question I take it its fine?)
This fixed most of my edited trooper tree - thank you!
BUT, other units that are not mentioned in party templates are not affected by this (Vigla Recuit and Bucellarii for example). Any idea how to fix this?
 
Upvote 0
Sorry for reviving a dead thread (but since you linked this thread as an answer to another question I take it its fine?)
This fixed most of my edited trooper tree - thank you!
BUT, other units that are not mentioned in party templates are not affected by this (Vigla Recuit and Bucellarii for example). Any idea how to fix this?
fI2Py.jpg

Worked for me.
 
Upvote 0
...
I was 100% sure I had everything correct. Thought I had changed helmet as example and removed upgradeables.
I had not, and actually doing it proved it worked.
Thx and sorry for wasting your time :smile:
 
Upvote 0
I'm having similiar issue, the xslt file remove the unit id but the XML doesn't replace it.
If the XmlNode of your SubModule.xml says:
<XmlName id="NPCCharacters" path="spnpccharacters"/>
It will look for spnpccharacters.xml (containing your new troops) and spnpccharacters.xslt (removing vanilla ones to avoid equipment pooling) in your mod's ModuleData folder. If you rename your xml file the engine won't find it, causing problems.

Alternatively, if you want to split it up, your SubModule.xml XmlNode could say something like this:
<XmlName id="NPCCharacters" path="troops"/>
Where "troops" or whatever is the name of a sub-folder in your ModuleData folder. In that case, the engine will sweep through all the files in that sub-folder (however they are individually named for convenience) picking up all the NPCCharacter id referenced changes. I presume you could put your spnpccharacters.xslt in that same folder but I always left that and an empty spnpccharacters.xml in my ModuleData folder referencing it and my troops sub-folder separately via two XmlNodes in my SubModule.xml (I doubt that or the empty spnpccharacters.xml is needed if your spnpccharacters.xslt and faction troop xmls are in the same referenced sub-folder).
 
Last edited:
Upvote 0
Solved, I left the placeholder text at the top of the .xml file.
Now how make it read the custom std_spnpccharacters_xml?

I have this inside "Languages" folder
<?xml version="1.0" encoding="utf-8"?>
<base xmlns:mad:si="http://www.w3.org/2001/XMLSchema-instance" xmlns:mad:sd="http://www.w3.org/2001/XMLSchema" type="string">
<tags>
<tag language="English" />
</tags>
<strings>

<string id="GEnwDYp1" text="Vlandian Recruit Custom" />

</strings>
</base>
node:
<XmlName id="GameText" path="std_spnpccharacters_xml"/>

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

<xsl:template match="string[@id='GEnwDYp1']"/>

</xsl:stylesheet>
 
Upvote 0
Back
Top Bottom